/**
 * Created by Administrator on 2017/4/5.
 */
$(function(){
    if (getQueryString('key') != '') {
        var key = getQueryString('key');
        var username = getQueryString('username');
        addCookie('key', key);
        addCookie('username', username);
    } else {
        var key = getCookie('key');
    }
    var username = ''
    if(key){
        $("#check_vr_code").on('click',function(){
            var code = $("#vr_code").val();
            if (code==''){
                creatLayout("请填写兑换验证码");
                return;
            }
            $.ajax({
                type:'post',
                url:ApiUrl+"/index.php?act=store&op=exchange&form_submit=ok&vr_code="+code,
                data:{key:key},
                dataType:'json',
                success:function(result){
                     if(result['code']==400){
                            creatLayout(result['msg']);
                            return;
                     }
                    //渲染模板
                    var html = template.render('order_html', result);
                    $(".res").html(html);
                }
            });
        })

    } else {

        window.location.href =  "login.html";
    }
});